import {Component, OnInit, Input, OnChanges, TemplateRef, ViewChild} from '@angular/core';
import * as echarts from 'echarts';
import {NzMessageService} from "ng-zorro-antd";
import {FetchService} from "../../../core/net/fetch.service";
import {FormBuilder, FormGroup} from "@angular/forms";
import {NzModalRef, NzModalService} from "ng-zorro-antd/modal";

@Component({
  selector: "app-zx-panel2",
  templateUrl: "./zx-panel2.component.html",
  styleUrls: ["./zx-panel2.component.scss"]
})
export class ZxPanel2Component implements OnInit {
  tplModal: NzModalRef;
  tableData1 = [];
  tableData2 = [];
  tableData3 = [];
  tableData4 = [];
  tableData5 = [];
  tableData6 = [];
  tableData7 = [];
  nzBodyStyle: any = {
    padding: '0px'
  };
  modalShow = false;
  private deployUrl = (window as any).environment.deployUrl;

  constructor(
    private message: NzMessageService,
    private fetchService: FetchService,
    private modal: NzModalService
  ) {
  }

  ngOnInit() {
    this.queryInfo();
  }

  queryInfo(reset: boolean = false): void {
    this.fetchService.post<any>("muw/wrsMuwWatReg/listLast", {}).subscribe(res => {
      this.tableData1 = res.slice(0, 1);
      this.tableData2 = res.slice(1, 2);
      this.tableData3 = res.slice(2, 8);
      this.tableData4 = res.slice(8, 9);
      this.tableData5 = res.slice(9, 13);
      this.tableData6 = res.slice(13, 18);
      this.tableData7 = res.slice(18, 23);
    });
  }

  showModal(tplContent: TemplateRef<{}>): void {
    const that = this;
    this.tplModal = this.modal.create({
      nzTitle: null,
      nzContent: tplContent,
      nzWidth: '100%',
      nzFooter: null,
      nzMaskClosable: false,
      nzStyle: {top: '0px', padding: '0px'},
      nzBodyStyle: {padding: '0px'},
      nzClosable: false,
      nzOnCancel(): void {
        console.log('modal destroy');
        that.destroyModal();
      }
    });

  }

  openJrsq(): void {
    window.open(`${this.deployUrl}/#/jrsq-screen`);
  }

  destroyModal() {
    this.tplModal.destroy();
  }
}
